<?php
/**
 * Created by lzl
 * Date: 2021 2021/9/14
 * Time: 10:07
 */
namespace App\Forms;

use App\Models\Article;

class ArticleForms extends BaseForm
{

    /**
     * 文章列表
     * @param $validated
     * @return mixed
     */
    public function articleList($validated)
    {
        $list = Article::where([])
            ->page($validated['page'], $validated['limit'])
            ->orderBy('id','desc')
            ->get();
        return $list;
    }


    /**
     * 修改文章
     * @param $validated
     * @return Article|\Illuminate\Database\Eloquent\Model
     */
    public function editArticle($validated)
    {
        return Article::updateOrCreate(['id' => $validated['id'] ?? 0 ], $validated);
    }


    /**
     * 文章详情
     * @param $validated
     * @return array
     */
    public function getArticleOrNew($validated)
    {
        $model =  Article::firstOrNew(['id' => $validated['id'] ?? 0]);

        return compact('model');
    }


}